package com.spzx.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spzx.common.core.utils.StringUtils;
import com.spzx.user.domain.Region;
import com.spzx.user.mapper.RegionMapper;
import com.spzx.user.service.IRegionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 地区信息表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2024-11-18
 */
@Service
public class RegionServiceImpl extends ServiceImpl<RegionMapper, Region> implements IRegionService {

    @Override
    public String getNameByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return "";
        }

        Region region = baseMapper.selectOne(
                new LambdaQueryWrapper<Region>()
                        .eq(Region::getCode, code)
                        .select(Region::getName)
        );

        if (null != region) {
            return region.getName();
        }
        return "";
    }

    @Override
    public List<Region> treeSelect(String parentCode) {
        return baseMapper.selectList(
                new LambdaQueryWrapper<Region>()
                        .eq(Region::getParentCode, parentCode));
    }
}
